package com.woniuxy.goods.user.controller;

import com.woniuxy.goods.module.result.Result;
import com.woniuxy.goods.module.user.User;
import com.woniuxy.goods.user.service.UserServcie;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
//@CrossOrigin
public class UserController {
    @Autowired
    UserServcie userServcie ;
    @Value("${server.port}")
    int port ;
    @PostMapping ("/user/login")
    public User loginApi(@RequestBody User user){
        log.info("本次访问的服务的端口号是：{}",this.port);
       /* try {
            //睡眠五秒钟
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/
        User nameAndPass = userServcie.findUserByNameAndPass(user.getUsername(), user.getPassword());
        return nameAndPass;
    }

    @GetMapping ("/user/findUserByKey/{id}")
    public User findUserByKey(@PathVariable("id") int id){
        log.info("本次访问的服务的端口号是：{}",this.port);
        User nameAndPass = userServcie.findUserByKey(id);
        return nameAndPass;
    }
}
